# -*- coding: utf-8 -*-

import scpy.xawesome_time as xawsome_time

import util


def purify(original, keyword, content, crawler_source, classify='news'):
    return {
        'createdAt': util.current_date(),
        'searchKey': keyword,
        'crawlerSource': crawler_source,
        'sourceClassify': classify,
        'time': xawsome_time.parse_time(original.get('datetime', '')),
        'source': util.ustr(original.get('source', '')),
        'title': util.ustr(original.get('title', '')),
        'abstract': util.ustr(original.get('abstract', '')),
        'keywords': util.ustr(original.get('keywords', '')),
        'url': original.get('url', ''),
        'content': content
    }


def purify_and_format(original, keyword, content, crawler_source, classify='news'):
    return {
        'createdAt': util.current_date(),
        'newsTime': xawsome_time.parse_time(original.get('datetime', '')),
        'crawlerSource': crawler_source,
        'sourceClassify': classify,
        'source': util.ustr(original.get('source', '')) if original.get('source', '') else crawler_source,
        'title': util.ustr(original.get('title', '')),
        'url': original.get('url', ''),
        'abstract': util.ustr(original.get('abstract', '')),
        'searchKey': keyword,
        'content': content
    }
